#pragma once
#include <SimpleDef.h>
extern void* DispatchSyscall;
#define __NR_WriteConsole (0) /* 打印字符串 */
#define __NR_CreateProcess (1) /* 创建进程 */
#define __NR_ReadCR3 (2) /* 读取 CR3 */ 
#define __NR_SetColor (3) /* 字符串颜色 */
#define __NR_GetChar (5)

#define _syscall0(type, name) \
static inline type name(void) \
{\
    __asm \
    { \
    __asm mov eax, __NR_##name \
    __asm int 0x80 \
    } \
}

#define _syscall1(type, name, type1, param1) \
static inline type name(type1 param1) \
{ \
_Static_assert(sizeof(type1) == 4, "Parameter size must be 4 bytes."); \
    __asm \
    {\
        __asm mov eax, __NR_##name \
        __asm mov ebx, param1 \
        __asm int 0x80 \
    } \
}

#define _syscall2(type, name, type1, param1, type2, param2) \
static inline type name(type1 param1, type2 param2) \
{ \
_Static_assert(sizeof(type1) == 4, "Parameter size must be 4 bytes."); \
_Static_assert(sizeof(type2) == 4, "Parameter size must be 4 bytes."); \
    __asm \
    {\
        __asm mov eax, __NR_##name \
        __asm mov ebx, param1 \
        __asm mov ecx, param2 \
        __asm int 0x80 \
    } \
}

#define _syscall3(type, name, type1, param1, type2, param2, type3, param3) \
static inline type name(type1 param1, type2 param2, type3 param3) \
{ \
_Static_assert(sizeof(type1) == 4, "Parameter size must be 4 bytes."); \
_Static_assert(sizeof(type2) == 4, "Parameter size must be 4 bytes."); \
_Static_assert(sizeof(type3) == 4, "Parameter size must be 4 bytes."); \
    __asm \
    {\
        __asm mov eax, __NR_##name \
        __asm mov ebx, param1 \
        __asm mov ecx, param2 \
        __asm mov edx, param3 \
        __asm int 0x80 \
    } \
}

#define _syscall4(type, name, type1, param1, type2, param2, type3, param3, type4, param4) \
static inline type name(type1 param1, type2 param2, type3 param3, type4 param4) \
{ \
_Static_assert(sizeof(type1) == 4, "Parameter size must be 4 bytes."); \
_Static_assert(sizeof(type2) == 4, "Parameter size must be 4 bytes."); \
_Static_assert(sizeof(type3) == 4, "Parameter size must be 4 bytes."); \
_Static_assert(sizeof(type4) == 4, "Parameter size must be 4 bytes."); \
    __asm \
    {\
        __asm mov eax, __NR_##name \
        __asm mov ebx, param1 \
        __asm mov ecx, param2 \
        __asm mov edx, param3 \
        __asm mov edx, param4 \
        __asm int 0x80 \
    } \
}



_syscall1(LONG, WriteConsole, LPCSTR, lpcStr)
_syscall4(HANDLE, CreateProcess, LPCSTR, lpApplicationName,LPCSTR, lpCommandLine, DWORD, dwCreationFlags, LPVOID, lpEnvironment)
_syscall0(DWORD, ReadCR3)
_syscall1(void, SetColor, int, nColor)
_syscall0(int, GetChar)